/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-10-11
 * Time: 20:39
 */
import java.util.*;
public class Main2 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * @param numbers int整型一维数组
     * @return int整型
     */
    public static int MoreThanHalfNum_Solution (int[] numbers) {
        if(numbers == null) return 0;
        if(numbers.length == 1) return numbers[0];
        // write code here
        Arrays.sort(numbers);
        int target = numbers[numbers.length >> 1];
        for(int num : numbers) {
            if(num == target) {
                return target;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = {1,2,2,2,2,1,3,2,2};
        System.out.println(MoreThanHalfNum_Solution(array));
    }
}
